package com.ling.service;

import com.ling.bean.Notification;
import com.ling.bean.NotificationExample;
import com.ling.dao.NotificationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NotificationService {
    private final NotificationMapper notificationMapper;

    @Autowired
    public NotificationService(NotificationMapper notificationMapper) {
        this.notificationMapper = notificationMapper;
    }

    //查询公告数据,按照添加时间，排序逆序
    public List<Notification> getAllNotification() {
        NotificationExample notificationExample = new NotificationExample();
        notificationExample.setOrderByClause("t_notification.editTime desc");
        return notificationMapper.selectByExample(notificationExample);
    }


    //保存公告
    public void saveNotification(Notification notification) {
        notificationMapper.insertSelective(notification);
    }

    //通过id来删除公告数据
    public void delNotification(String id) {
        notificationMapper.deleteByPrimaryKey(id);
    }

    //修改公告,需要注意，在调用此方法时，此对象id需要设定
    public void updateNotification(Notification notification) {
        notificationMapper.updateByPrimaryKeySelective(notification);
    }

    //获取指定id的公告
    public Notification getNotificationById(String id){
        return notificationMapper.selectByPrimaryKey(id);
    }
}
